/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.mall.biz.rebateFreeze.service.impl;

import co.yixiang.common.core.utils.FileUtil;
import co.yixiang.common.mproot.common.service.impl.BaseServiceImpl;
import co.yixiang.common.mproot.common.utils.QueryHelpPlus;
import co.yixiang.common.mproot.domain.PageResult;
import co.yixiang.common.mproot.dozer.service.IGenerator;
import co.yixiang.mall.biz.rebateFreeze.mapper.UserRebateFreezeMapper;
import co.yixiang.mall.biz.rebateFreeze.service.UserRebateFreezeService;
import co.yixiang.mall.common.rebateFreeze.domain.UserRebateFreeze;
import co.yixiang.mall.common.rebateFreeze.dto.UserRebateFreezeDto;
import co.yixiang.mall.common.rebateFreeze.dto.UserRebateFreezeQueryCriteria;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;

/**
* @author wangxueliang
* @date 2021-03-22
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "UserRebateFreeze")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserRebateFreezeServiceImpl extends BaseServiceImpl<UserRebateFreezeMapper, UserRebateFreeze> implements UserRebateFreezeService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public PageResult<UserRebateFreezeDto> queryAll(UserRebateFreezeQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<UserRebateFreeze> page = new PageInfo<>(queryAll(criteria));
        return generator.convertPageInfo(page,UserRebateFreezeDto.class);
    }


    @Override
    //@Cacheable
    public List<UserRebateFreeze> queryAll(UserRebateFreezeQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(UserRebateFreeze.class, criteria));
    }


    @Override
    public void download(List<UserRebateFreezeDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (UserRebateFreezeDto UserRebateFreeze : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("用户id", UserRebateFreeze.getUserId());
            map.put("冻结金额", UserRebateFreeze.getMoney());
            map.put("冻结积分", UserRebateFreeze.getScore());
            map.put("冻结开始时间", UserRebateFreeze.getStartTime());
            map.put("冻结结束时间", UserRebateFreeze.getEndTime());
            map.put("冻结状态：1冻结中,2已发放,3已取消", UserRebateFreeze.getState());
            map.put("冻结金额(礼包商品)", UserRebateFreeze.getAccumulativeAmount());
            map.put("订单id", UserRebateFreeze.getOrderId());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

    @Override
    public boolean saveBatch(Collection<UserRebateFreeze> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<UserRebateFreeze> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<UserRebateFreeze> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(UserRebateFreeze entity) {
        return false;
    }

    @Override
    public UserRebateFreeze getOne(Wrapper<UserRebateFreeze> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<UserRebateFreeze> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<UserRebateFreeze> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

}
